package net.zoneland.zrdp.biz.controller;

import javax.annotation.Resource;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import net.zoneland.zrdp.biz.domain.pojo.vo.IndicatorExcelDTO;
import net.zoneland.zrdp.biz.service.IIndicatorDataService;
import net.zoneland.zrdp.common.annotation.Log;
import net.zoneland.zrdp.common.core.controller.BaseController;
import net.zoneland.zrdp.common.core.domain.AjaxResult;
import net.zoneland.zrdp.common.enums.BusinessType;
import net.zoneland.zrdp.common.utils.poi.ExcelProcessor;

/**
 * 指标库数据Controller.
 * 创建日期: 2024-03-16
 * @author helu
 */
@RestController
@RequestMapping("/biz/data")
public class IndicatorDataController extends BaseController {

    /** 指标excel表格的标题行数量. **/
    private static final int EXCEL_TITLE_ROWS = 2;

    @Resource
    private IIndicatorDataService indicatorDataService;


    /**
     * 指标库导入.
     * @author helu
     * @Date 13:24 2024/3/20
     * @param file 文件
     * @return net.zoneland.zrdp.common.core.domain.AjaxResult
     */
    @Log(title = "指标库数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('biz:data:import')")
    @PostMapping("/import-data")
    public AjaxResult importData(final MultipartFile file) throws Exception {
        return success(indicatorDataService.importIndicator(new ExcelProcessor<>(IndicatorExcelDTO.class)
            .importExcel(file.getInputStream(), EXCEL_TITLE_ROWS)));
    }
}
